package kayao.client.data;

import kayao.client.network.message.MessageHandler;
import kayao.client.network.message.MissionMessage;
import kayao.common.KayaoValues;

public class MissionHandler {
	
	static int mMissionId = -1;
	static boolean completedMission = false;

	static float mFlagPosX;
	static float mFlagPosY;
	static float mFlagPosZ;
	
	static boolean hasCollided = false;
	static boolean hasFlag = false;
		
	public static void newMission(int mId,float x,float y,float z){
//		if(!completedMission){
//			// TODO Do something if not yet completed mission
//			// or just start the new one immediately?
//		}
//		
//		// If mission id is same as we're in it just means
//		// flag position has changed.
//		if(mMissionId == mId){
//			setFlag(x,y,z);
//			return;
//		}			
		mMissionId = mId;
		mFlagPosX = x;
		mFlagPosY = y;
		mFlagPosZ = z;
		hasCollided = false;
		hasFlag = false;
		SharedMemory.getInstance().updateFlag();
		System.out.println("[MissionHandler] - New mission: "+mMissionId+ " "+ x+" "+ y+" "+ z);
	}
	
	public static int getMissionId(){
		return mMissionId;
	}

	public static float getFlagPosX(){
		return mFlagPosX;
	}

	public static float getFlagPosY(){
		return mFlagPosY;
	}

	public static float getFlagPosZ(){
		return mFlagPosZ;
	}
	
	public static Float[] getFlagPosXYZ(){
		return new Float[]{mFlagPosX,mFlagPosX,mFlagPosX};
	}
	
	public static void setFlag(float x, float y, float z){
		mFlagPosX = x;
		mFlagPosY = y;
		mFlagPosZ = z;
	}
	
	public static boolean hasCollided(){
		return hasCollided;
	}
	
	public static boolean hasFlag(){
		return hasFlag;
	}
	
	public static void tookFlag(){
		hasFlag = true;
		MessageHandler.insertOutgoingMessage(new MissionMessage(KayaoValues.SERVER_IP, false));
	}
	
	public static void lostFlag(){
		hasFlag = false;
	}
}
